package system

import (
	"errors"
	"os"
	"runtime"
	"strings"
)

func GetSerialNumber() (string, error) {
	if runtime.GOOS != "linux" {
		return "", errors.New("GetSerialNumber 仅支持在 Linux 系统上运行")
	}
	const serialFile = "/sys/class/dmi/id/product_serial"
	if _, err := os.Stat(serialFile); err != nil {
		if os.IsNotExist(err) {
			return "", errors.New("序列号文件不存在")
		}
		return "", err
	}
	data, err := os.ReadFile(serialFile)
	if err != nil {
		return "", err
	}
	return strings.TrimSpace(string(data)), nil
}
